<?php
//总的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$recoveryeswhere      = "";
if($startdate!="" && $enddate!=""){
  $recoverwhere    = " and recover_time>='$startdate' and  recover_time<='$enddate'";
  $recoveryeswhere    = " and recover_yestime>='$startdate' and  recover_yestime<='$enddate'";    
} 
$rows = $dbselect->GetRows("SELECT recover_time as '待收时间', SUM(recover_account) AS '待收总额', COUNT(recover_account) AS '次数',
SUM(recover_interest) AS '利息', sum(recover_capital) AS '本金'
FROM 05b_2list_recover
WHERE  1 $recoverwhere
GROUP BY recover_time ");
foreach($rows as &$row)
{   
    $ctime  = $row['待收时间'];
    $r_a    = $row['待收总额'];
    $r_c    = $row['本金'];
    $r_i    = $row['利息'];
    $r_o    = $row['其他费用'];
    $count  = $row['次数'];
    if($count>0){
        CTLog::G()->pxxDayReal($count.",sid",1,'投资_待收_总',$r_a,$ctime);
        CTLog::G()->pxxDayReal($count.",sid",1,'投资_待收_本',$r_c,$ctime);
        CTLog::G()->pxxDayReal($count.",sid",1,'投资_待收_利',$r_i,$ctime);  
    }
}

//正常还款的

$rows = $dbselect->GetRows("SELECT recover_yestime as '还款时间', SUM(recover_account_yes) AS '还款总额', COUNT(recover_account_yes) AS '次数',
SUM(recover_interest_yes) AS '还款利息', sum(recover_capital_yes) AS '还款本金',
COUNT(DISTINCT uid) as 已收人数,
SUM(late_interest+late_forfeit+late_reminder) AS '其他费用',SUM(if((late_interest+late_forfeit+late_reminder)>0,1,0)) AS '其他费用次'
FROM 05b_2list_recover
WHERE recover_status=1 $recoveryeswhere
GROUP BY  recover_yestime ");
foreach($rows as &$row)
{   
    $ctime  = $row['还款时间'];
    $r_a    = $row['还款总额'];
    $r_b    = $row['已收人数'];
    $r_c    = $row['还款本金'];
    $r_i    = $row['还款利息'];
    $r_q    = $row['其他费用'];
    $count  = $row['次数'];
    $c_li   = $row['其他费用次'];

    if($r_a>0){
        CTLog::G()->pxxDayReal($count.",sid",1,"投资_已收_总",$r_a,$ctime); //分站统计 
    }
    if($r_b>0){
        CTLog::G()->pxxDayReal("sid",1,"投资_已收_人数",$r_b,$ctime); //分站统计 
    }
    if($r_c>0){
        CTLog::G()->pxxDayReal($count.",sid",1,"投资_已收_本",$r_c,$ctime); //分站统计   
    }
    if($r_i>0){
        CTLog::G()->pxxDayReal($count.",sid",1,"投资_已收_利",$r_i,$ctime); //分站统计  
    }
    if($r_q>0){
        CTLog::G()->pxxDayReal($c_li.",sid",1,"投资_已收_其他",$r_q,$ctime); //分站统计 
    }
}
